$(function () {
  // 获取顶部的统计数据
  $.ajax({
    url: BigNew.data_info,
    success (backData) {
      //   console.log(backData)
      // 总文章数
      $('.spannel:first')
        .find('em')
        .text(backData.totalArticle)
      // 日新增文章数
      $('.scolor01')
        .find('em')
        .text(backData.dayArticle)

      // 评论总数
      $('.scolor02')
        .find('em')
        .text(backData.totalComment)

      // 日新增评论数
      $('.scolor03')
        .find('em')
        .text(backData.dayComment)
    }
  })

  // 获取日新增文章数量统计
  $.ajax({
    url: BigNew.data_article,
    success (backData) {
      console.log(backData)
      //   var json = backData.data
      //     '{"code":200,"msg":"获取成功","date":[{"date":"2019-05-20","count":23},{"date":"2019-05-21","count":19},{"date":"2019-05-22","count":29},{"date":"2019-05-23","count":24},{"date":"2019-05-24","count":28},{"date":"2019-05-25","count":28},{"date":"2019-05-26","count":19},{"date":"2019-05-27","count":25},{"date":"2019-05-28","count":25}]}'
      var obj = backData
      loadEchars(obj)

      function loadEchars (obj) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('curve_show'))

        var data = []
        var date = []
        for (var i = 0; i < obj.date.length; i++) {
          data.push(obj.date[i].count)
          date.push(obj.date[i].date)
        }

        option = {
          tooltip: {
            trigger: 'axis',
            position: function (pt) {
              return [pt[0], '10%']
            }
          },
          title: {
            left: 'center',
            text: '月新增文章数'
          },

          xAxis: {
            name: '日',
            type: 'category',
            boundaryGap: false,
            data: date
          },
          legend: {
            data: ['新增文章'],
            top: '40'
          },
          toolbox: {
            show: true,
            feature: {
              dataZoom: {
                yAxisIndex: 'none'
              },
              dataView: { readOnly: false },
              magicType: { type: ['line', 'bar'] },
              restore: {},
              saveAsImage: {}
            },
            right: 50
          },
          yAxis: {
            type: 'value',
            boundaryGap: [0, '100%']
          },
          series: [
            {
              name: '新增文章',
              type: 'line',
              smooth: true,
              // symbol: 'none',
              sampling: 'average',
              itemStyle: {
                color: '#f80'
              },
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: 'rgba(255,136,0,0.39)'
                  },
                  {
                    offset: 0.34,
                    color: 'rgba(255,180,0,0.25)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(255,222,0,0.00)'
                  }
                ])
              },
              data: data
            }
          ]
        }
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option)
      }
    }
  })
})
